#include "core/main.h"

Directory::Directory(const string &path)
{
    Load(path);
}

void Directory::Load(const string &path)
{

    _path = path + "\\";
    _files.clear();
    _directories.clear();

#ifdef WIN32
    WIN32_FIND_DATA findResult;
    //LARGE_INTEGER fileSize;
    
    HANDLE hFind = FindFirstFile((path + string("\\*")).c_str(), &findResult);

    if (hFind == INVALID_HANDLE_VALUE)
    {
        return;
    } 

    do
    {
        if (findResult.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
        {
            string directoryName(findResult.cFileName);
            if(directoryName != string(".") &&
               directoryName != string("..") &&
               directoryName != string(".svn"))
            {
                _directories.push_back(directoryName);
            }
        }
        else
        {
            //FileSize.LowPart = FindResult.nFileSizeLow;
            //FileSize.HighPart = FindResult.nFileSizeHigh;
            _files.push_back(string(findResult.cFileName));
        }
    }
    while (FindNextFile(hFind, &findResult) != 0);

    FindClose(hFind);

#else

    Assert(false, "Implement Linux Directory::Load");

#endif
}

/*vector<string> Directory::FilesWithSuffix(const string &suffix) const
{
    vector<string> result;
    for(UINT fileIndex = 0; fileIndex < _files.Length(); fileIndex++)
    {
        const string &curFilename = _files[fileIndex];
        if(curFilename.EndsWith(suffix))
        {
            result.PushEnd(curFilename);
        }
    }
    return result;
}*/
